package com.ysy.logistics.permission;

import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;
import com.ysy.common.resp.ResultData;
import com.ysy.logistics.entities.system.dto.SysUserDTO;
import com.ysy.logistics.service.system.SysUserService;
import jakarta.annotation.Resource;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassDescription: Sa-Token权限验证接口实现类
 * @Author:姚斯羽
 * @Create:2025/3/12 14:17
 **/
public class StpInterfaceImpl implements StpInterface {
    @Resource
    private SysUserService sysUserService;
    /**
     * 权限列表
     * @param loginId
     * @param s
     * @return
     */
    @Override
    public List<String> getPermissionList(Object loginId, String s) {
        if (!StpUtil.isLogin()) {
            return null;
        }
        //根据登录信息
        ResultData<SysUserDTO> userInfoById = sysUserService.getUserInfoById((String) loginId);

        if (!userInfoById.successFlag()){
            return null;
        }
        SysUserDTO userInfo = userInfoById.getData();

        //权限列表
        List<String> permissions = new ArrayList<>();
        //通用权限
        permissions.add("common");
        //如果是admin则返回全部权限
        if ("admin".equals(userInfo.getUsername())){
            permissions.add("all");
        }
        //获取用户权限

        //获取角色列表

        //获取角色权限

        return permissions;

    }

    /**
     * 角色列表
     * @param o
     * @param s
     * @return
     */
    @Override
    public List<String> getRoleList(Object o, String s) {
        return null;
    }
}

